package com.wanxi.springboot.team.manage.system.controller;


import com.wanxi.springboot.team.manage.system.api.CommonResult;
import com.wanxi.springboot.team.manage.system.model.Role;
import com.wanxi.springboot.team.manage.system.service.RoleService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 蒋帆
 * @since 2020-12-21
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    RoleService roleService;

//    @PreAuthorize("hasAnyAuthority('role:get:list')")
    @GetMapping("/getRoleList")
    public CommonResult getRoleList(){
        return roleService.getRoleList();
    }

    @PreAuthorize("hasAnyAuthority('role:get:all')")
    @GetMapping("/getRoles")
    public CommonResult getRoles(@RequestParam("page") Integer page,@RequestParam("limit") Integer limit){
        return roleService.getRoles(page,limit);
    }

    @PreAuthorize("hasAnyAuthority('role:add')")
    @PostMapping("/addRole")
    public CommonResult addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }

    @PreAuthorize("hasAnyAuthority('role:update')")
    @PostMapping("/updateRole")
    public CommonResult updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }

    @PreAuthorize("hasAnyAuthority('role:delete')")
    @PostMapping("/deleteRole")
    public CommonResult deleteRole(@RequestParam Integer id){
        return roleService.deleteRole(id);
    }
}
